<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.js"></script> -->

		<!-- 预加载，这个资源空闲时加载，一般用以加载其它路由资源. 即使页面关闭，prefetch 发起的请求仍会进行不会中断。 -->
		<link rel="prefetch" href="https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.js" />
	</head>

	<body>
		<button id="btn">加载js</button>

		<script>
			// 2. 加载js
			const btn = document.getElementById('btn');
			btn.onclick = function () {
				const script = document.createElement('script');
				script.src = 'https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.js';
				document.body.appendChild(script);
				script.onload = function () {
					console.log('加载成功', Vue);
				};
			};

			// 1. 报错
			console.log(Vue);
		</script>
	</body>
</html>
